<template>
	<view class="workbench">
		<uni-nav-bar dark :fixed="true" :border="false" background-color="#FFFFFF" status-bar 
			title="工作台" color="#000" />
		<!-- <view style="width: 100%; height: 145rpx;background-color: #ffffff;"></view> -->
		<view class="internal-management" v-for="(item,itemIndex) in dataRow" :key="itemIndex"
			v-if="item.rows.length > 0">
			<view class="workbench-title">{{item.title}}</view>
			<view class="feature-module">
				<view class="feature" v-for="(row,index) in item.rows" :key="index"
					@click="toPage(row.url,row.path)" v-if="row.hidden">
					<view class="feature-style">
						<image :src="row.img"></image>
					</view>
					<view style="width: 100%;text-align: center;">{{row.name}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from "../../request/api.js";
	export default {
		data() {
			return {
				userInfo: {},
				menuPath: [],
				menuPathMap: new Map(),
				dataRow: [{
					title: "内部管理",
					rows: []
					},{
					title: "客户管理",
					rows: []
					},{
					title: "仓库管理",
					rows: []
					},{
					title: "财务管理",
					rows: []
					},{
					title: "刀模生产部",
					rows: []
					},
				]
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("loginUser")
			this.menuPath = uni.getStorageSync("MenuPath")
			// console.log("menuRoute===>",this.menuPath)
			this.initMenu();
			this.initRow();
		},
		onShow() {
			this.getMsgList();
		},
		methods: {
			//页面跳转
			toPage(url,path) {
				if (path !== ""){
					uni.navigateTo({
						url:url+"?path="+path
					})
				}else {
					uni.navigateTo({
						url:url
					})
				}
			},
			// 初始化菜单
			initMenu(){
				this.menuPath.forEach(item =>{
					// 拆分字符串
					let parts = item.split("/");
					if (this.menuPathMap.has(parts[1])){
						this.menuPathMap.get(parts[1]).push(item);
					}else {
						let menuPathList = [];
						menuPathList.push(item);
						this.menuPathMap.set(parts[1],menuPathList);
					}
				})
				// console.log("menuPathMap===>",this.menuPathMap)
			},
			// 查消息条数
			getMsgList(){
				const data = {
					currentPage: 1,
					pageSize: 10,
					msgStatus: 0,
				}
				api.getMsgNotificationList(data).then(res =>{
					if (res.code === 200){
						if (res.data.total > 0){
							uni.setTabBarBadge({
								index: 2,
								text: res.data.total.toString()
							})
						}else {
							uni.removeTabBarBadge({
								index: 2
							});
						}
					}
				})
			},
			// 初始化
			initRow(){
				// 内部管理
				this.dataRow[0].rows = [{
						url: "/pages_clockIn/index/index",
						img: "../../static/workbench/internal/clock.png",
						name: "打卡",
						path: "",
						hidden: true,
					}, 
					{
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/examine.png",
						name: "考勤审批",
						path: "/employeeAttendance/apply",
						hidden: this.menuPath.indexOf("/employeeAttendance/apply") > -1,
					},
					{
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/work-summary.png",
						name: "每日总结",
						path: "/workRecords/DailySummary",
						hidden: this.menuPath.indexOf("/workRecords/DailySummary") > -1
					}, 
					{
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/expense.png",
						name: "报销申请",
						path: "/expense/Expense",
						hidden: this.menuPath.indexOf("/expense/Expense") > -1
					},
					{
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/order.png",
						name: "订单列表",
						path: "/order/orderList",
						hidden: this.menuPath.indexOf("/order/orderList") > -1
					}, 
					
					{
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/after-sale.png",
						name: "售后派单",
						path: "/afterSales/AfterDispatch",
						hidden: this.menuPath.indexOf("/afterSales/AfterDispatch") > -1
					}, {
						url: "/pages/workbench/webView",
						img: "../../static/workbench/internal/profile.png",
						name: "档案管理",
						path: "/goods/goods",
						hidden: this.menuPath.indexOf("/goods/goods") > -1
					}, 
				];
				// 客户管理
				if (this.menuPathMap.has("user")){
					this.dataRow[1].rows = [
						{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/client/client-list.png",
							name: "客户列表",
							path: "/user/user",
							hidden: this.menuPath.indexOf("/user/user") > -1
						},{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/client/gh.png",
							name: "公海列表",
							path: "/user/waiter",
							hidden: this.menuPath.indexOf("/user/waiter") > -1
						}, 
					];
				}
				// 仓库管理
				if (this.menuPathMap.has("warehouse")){
					this.dataRow[2].rows = [
						{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/warehouse/purchase.png",
							name: "采购管理",
							path: "/warehouse/purchase/purchasing",
							hidden: this.menuPath.indexOf("/warehouse/purchase/purchasing") > -1
						},{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/warehouse/rk.png",
							name: "入库管理",
							path: "/warehouse/warehouse",
							hidden: this.menuPath.indexOf("/warehouse/warehouse") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/warehouse/repertory.png",
							name: "库存管理",
							path: "/warehouse/lnventory/lnventory",
							hidden: this.menuPath.indexOf("/warehouse/lnventory/lnventory") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/warehouse/ck.png",
							name: "出库管理",
							path: "/warehouse/outbound/outbound",
							hidden: this.menuPath.indexOf("/warehouse/outbound/outbound") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/warehouse/return.png",
							name: "归还管理",
							path: "/warehouse/devicesReturn",
							hidden: this.menuPath.indexOf("/warehouse/devicesReturn") > -1
						}, 
					];
				}
				// 财务管理
				if (this.menuPathMap.has("finance")){
					this.dataRow[3].rows = [
						{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/finance/statistics.png",
							name: "报表统计",
							path: "/finance/billingReport",
							hidden: this.menuPath.indexOf("/finance/billingReport") > -1
						},{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/finance/disburse.png",
							name: "支出明细",
							path: "/finance/Income",
							hidden: this.menuPath.indexOf("/finance/Income") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/finance/income.png",
							name: "收款明细",
							path: "/finance/DetailPayment",
							hidden: this.menuPath.indexOf("/finance/DetailPayment") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/finance/account.png",
							name: "账户管理",
							path: "/finance/Account",
							hidden: this.menuPath.indexOf("/finance/Account") > -1
						}, 
					];
				}
				// 刀模生产部
				if (this.menuPathMap.has("die")){
					this.dataRow[4].rows = [
						{
							url: "/pages/workbench/webView",
							img: "../../static/workbench/die/client.png",
							name: "刀模客户",
							path: "/die/custom",
							hidden: this.menuPath.indexOf("/die/custom") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/die/order.png",
							name: "刀模订单",
							path: "/die/orders",
							hidden: this.menuPath.indexOf("/die/orders") > -1
						}, {
							url: "/pages/workbench/webView",
							img: "../../static/workbench/die/statistics.png",
							name: "刀模统计",
							path: "/die/statistics",
							hidden: this.menuPath.indexOf("/die/statistics") > -1
						},
					];
				}
			}
		}
	}
</script>

<style>
/* 	page {
		background-color: #f1f1f1;
	} */

	.workbench {
		width: 100%;
		min-height: 100vh;
		background-color: #9e9e9e26;
	}

	.internal-management {
		width: 90%;
		margin: auto;
		margin-top: 15rpx;
		background-color: #ffffff;
		padding: 20rpx;
		border-radius: 15rpx;
	}

	.workbench-title {
		font-size: 35rpx;
		color: #9E9E9E;
	}

	.feature-module {
		display: flex;
		flex-wrap: wrap;
		/* justify-content: center; */
	}

	.feature {
		width: 160rpx;
		/* height: 120rpx; */
		padding: 20rpx;
		margin: 15rpx 7rpx;
		font-size: 35rpx;
	}

	.feature-style {
		font-size: 35rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.feature image {
		width: 70rpx;
		height: 70rpx;
	}
</style>